<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
</head>
<body>	
</body>
</html>
<?php 
	function M($oldPath,$newPath,$num = 0 ){
	//第一个参数是提取路径，第二个是目标路径，第三个是选填{不填代表克隆，1代表移动}		
		$preg = "/\/$/";
		$preg1 = "/^\./";
		$inner_OldPath = preg_replace($preg, '', $oldPath);
		$inner_NewPath = preg_replace($preg, '', $newPath);
		$son_path = glob($inner_OldPath.'/*');
		mkdir($inner_NewPath.$inner_OldPath);
		foreach ($son_path as $value) {
			if(is_dir($value)){					
				M($value,$newPath,$num = 0);
			}else{					
				$path = preg_replace($preg1, '', $value);
				copy($value,$inner_NewPath.$path);
			}
		}
		if($num == 1){
			del($oldPath);
		}		
	}
	M("./t/","./t2");

	function del($path)
	{
		$preg = "/\/$/";
		$newPath = preg_replace($preg, '', $path);
		$sons = glob($newPath.'/*');
		if(empty($sons)){
			rmdir($newPath);
		}else{
			foreach ($sons as $value) {
				if(is_dir($value)){
					del($value);
				}else{
					unlink($value);
				}
				
			}
			rmdir($newPath);
		}
	}



 ?>